<template>
<van-nav-bar
  title="订单详情"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>
<p style="float: right;color: red;" v-if ="order.status == 1 "><span>状态：</span>待支付</p>
<p style="float: right;color:dodgerblue; "v-else ="order.status == 1 "><span>状态：</span>已支付</p>
<p><span>订单号：</span>{{order.ordernum}}</p>
<p><span>发起人：</span>{{order.user?.name||''}}</p>
<p><span>下单时间：</span>{{order.create_time}}</p>
<p><span>服务：</span>{{order.name}}</p>
<p><span>购买数量：</span>{{order.num}}</p>
<!-- <p><span>使用设备：</span>{{order.equip?.name||''}}</p> -->
<!-- <p><span>营业点：</span>{{order.outlet?.name||''}}</p> -->
<!-- <p><span>使用优惠券：</span>{{order.couponname}}</p> -->
<!-- <p><span>使用积分：</span>{{order.usedscore}}</p> -->
<p><span>应付：</span>{{order.price*1.2}}</p>
<p><span>实付：</span>{{order.price}}</p>
<div v-if="order.status=='1'">
  <van-button type="primary" @click="onClickLeft">取消订单</van-button>
  <van-button type="primary" @click="pay">确认支付</van-button>
</div>

</template>
<script setup>
import axios from 'axios'
import { ref,onMounted } from 'vue'
import { useRouter, useRoute} from 'vue-router'
const router = useRouter()
const route = useRoute()
const onClickLeft = () => {
  router.back()
}
let order = ref({})
const getOrder = () => {
  axios.get(`http://127.0.0.1:8000/order/detail/`,{params:{ordernum:route.query.ordernum}})
  .then(res=>{
    console.log(res.data)
    order.value = res.data.data
  })
}
const pay = () => {
  axios.post(`http://127.0.0.1:8000/order/link/`,{ordernum:route.query.ordernum}).then(res=>{
    console.log(res.data.data)
    window.location.href = res.data.data
  })
}

onMounted(()=>{
  getOrder()
})
</script>